package ar.edu.unq.wannaplay.utils;

import java.util.HashMap;
import java.util.Map;

public class Matrix {

    private Map<Integer, Map<Integer, Info>> baseMatrix = new HashMap<Integer, Map<Integer, Info>>();

    private int height;

    private int width;

    public Matrix(final int rows, final int cols, final Info info) {
        width = rows;
        height = cols;
        for (int i = 0; i < rows; i++) {
            baseMatrix.put(i, new HashMap<Integer, Info>());
            for (int j = 0; j < cols; j++) {
                baseMatrix.get(i).put(j, info.cloneInfo());
            }
        }
    }

    public void addElem(final Integer iCoor, final Integer jCoor, final Object elem, final CalendareableState state) {
        baseMatrix.get(iCoor).get(jCoor).addElem(elem, state);
    }

    public Info getInfo(final int iCoor, final int jCoor) {
        return baseMatrix.get(iCoor).get(jCoor);
    }

    public void removeElem(final int iCoor, final int jCoor, final Object elem) {
        baseMatrix.get(iCoor).get(jCoor).removeElem(elem);
    }

    public Map<Integer, Map<Integer, Info>> getBaseMatrix() {
        return baseMatrix;
    }

    public void setBaseMatrix(final Map<Integer, Map<Integer, Info>> baseMatrix) {
        this.baseMatrix = baseMatrix;
    }

    @Override
    public String toString() {
        StringBuffer totalString = new StringBuffer("");

        for (int i : baseMatrix.keySet()) {
            totalString.append("\n");// NOPMD
            for (int j : baseMatrix.get(i).keySet()) {
                totalString.append(baseMatrix.get(i).get(j).toString());
            }
        }

        return totalString.toString();
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(final int height) {
        this.height = height;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(final int width) {
        this.width = width;
    }
}
